package net;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Queue;

public class quanlyclient extends Thread {
	private ServerSocket server;
	private ObjectOutputStream out=null;
	private ObjectInputStream in=null;
	private Queues<msg> Sendqueue;
	private Queues<msg> CMDqueue;
	private ArrayList<tonghopdocghi>array;
	
	public quanlyclient(){}
	public quanlyclient(ServerSocket server,  Queues<msg> CMDqueue, Queues<msg>Sendqueue, ArrayList<tonghopdocghi>array)
	{
		super();
		this.server=server;
		
		this.CMDqueue=CMDqueue;
		this.Sendqueue=Sendqueue;
		this.array=array;
		
		
		
	}

	public void run()
	{
		int toi=0;
		while(true)
		{
			 Socket socket;
				try {
					
					socket = server.accept();//socket se ghi nho dia chi ip cua client 
					System.out.println("ban chay duoc roi "+socket.getInetAddress().getHostName());
				
					 
					out=new ObjectOutputStream(socket.getOutputStream());
					 
					in=new ObjectInputStream(socket.getInputStream());
					
					
					
					tonghopdocghi tonghop=new tonghopdocghi(in, out, CMDqueue,Sendqueue,socket);
					
						
				
					tonghop.start();
					
					array.add(tonghop);	
					
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				 
				
		}
		
	}
}
